<#include "/common/include.html"/>
<@pageTheme mark="${config.optimize()?string('true', 'false')}">
    <@header title="待办任务">
    </@header>
    <@search fromId="form-form">
        <div class="select-list">
            <ul>
                <li>
                    <@ctx.i18n text = "实例名称"/>：
                    <input type="text" name="userName"/>
                </li>
                <li>
                    <@ctx.i18n text = "发起人"/>：
                    <input type="text" name="leaveDays"/>
                </li>
                <li>
                    状态：
                    <select name="status">
                        <option value="">所有</option>
                    </select>
                </li>
                <li>
                    <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;&nbsp;<@ctx.i18n text = "查询"/></a>
                    <a class="btn btn-warning btn-rounded btn-sm" onclick="opt.form.reset()"><i class="fa fa-refresh"></i>&nbsp;<@ctx.i18n text = "重置"/></a>
                </li>
            </ul>
        </div>
    </@search>
    <@table tableId="bootstrap-table">
    </@table>
    <@footer>
        <script>
            var delFlag = "${permission.hasPermi("bpm:processInstance:del")}";
            var leaveTypeDatas = ${dict.getDictListJson('sys_leave_type')};
            var statusDatas = ${dict.getDictListJson('sys_bpm_status')};
            var priorityDatas = ${dict.getDictListJson('sys_bpm_priority')};
            var prefix = baseURL + "bpm/task";
            $(function() {
                var options = {
                    url: prefix + "/applaying/list",
                    showSearch: false,
                    showRefresh: false,
                    showToggle: false,
                    showColumns: false,
                    clickToSelect: true,
                    uniqueId:    'id'                                   , /* 唯一ID */
                    columns: [
                        {title: $.i18n.prop("序号"), width: 5, align: "center", formatter: function (value, row, index) {
                            return $.table.serialNumber(index);
                        }},
                        {field : 'saleCode',title : '<@ctx.i18n text = "订单编号"/>'},
                        {field : 'formName',title : '<@ctx.i18n text = "任务名称"/>'},
                        {field : 'taskName',title : '<@ctx.i18n text = "当前流程"/>'},
                        {field : 'userName',title : '<@ctx.i18n text = "发起人"/>'},
                        {field : 'startTime',title : '<@ctx.i18n text = "开始时间"/>',width: 170},
                        // ,{field : 'priority',title : '<@ctx.i18n text = "优先级"/>',formatter: function(value, row, index) {
                        //         return $.table.selectDictLabel(priorityDatas, value);}},
                        {field : 'status',title : '<@ctx.i18n text = "状态"/>',formatter: function(value, row, index) {
                                return $.table.selectDictLabel(statusDatas, value);}},
                        {title:"<@ctx.i18n text = "操作"/>",class:'action',formatter: function(value, row, index) {
                                var actions = [];
                                actions.push('<a class="" href="javascript:void(0)" title="<@ctx.i18n text = "流程跟踪"/>" onclick="preview(\'' + row.processInstanceId + '\')"><i class="fa icon-picture"></i></a> ');
                                actions.push('<a class="" href="javascript:void(0)" title="<@ctx.i18n text = "办理"/>" onclick="handle(\''+row.taskId+'\',\'' + row.businessKey + '\',\''+row.formKey+'\',\''+row.taskName+'\',\''+row.id+'\')"><i class="fa icon-check"></i></a> ');
                                return actions.join('');
                        }}
                    ]
                };
                $.table.init(options);
            });

            /*预览*/
            function preview(id) {
                var options = {
                    url: baseURL + "bpm/processInstance/preview/" + id,
                    title: '<i class="fa icon-loop"></i> <@ctx.i18n text = "流程跟踪"/>',
                    btn:['<i class="fa fa-close"></i> '+$.i18n.prop("取消")],
                    width: $(top.window).width() - 300,
                    height: $(top.window).height() - 200
                };
                opt.modal.openMainWin(options);
            }

            /*处理*/
            function handle(taskId,businessKey,formKey,taskName,id){
                if(taskName=='取消订单'){
                    opt.warning("请在订单详情中处理");
                    return;
                }
               else if(taskName=='车辆申请单'){
                    opt.modal.open('<i class="fa icon-note"></i> <@ctx.i18n text = "选择车辆"/>',
                        baseURL  +"bpm/carinfo/select/"+taskId+"/"+id,"1600","",selectcar,true);
                }
                else if(taskName=='申请报销'){
                    opt.modal.open("申请报销",baseURL+"bpm/reimburse/add/"+taskId+"/"+id);
                }
                else if(taskName=='提供收款信息'){
                    opt.modal.open("提供收款信息",baseURL+ "bpm/collectionmoney/add/"+id);
                }
                else if(taskName=='置换申请'){
                    opt.modal.open("置换申请",baseURL+ "bpm/substitution/add/"+id);
                }
                else if(taskName=='提供客户信息'){
                    opt.modal.open("提供客户信息",baseURL+ "bpm/loan/add/"+id);
                }
                else if(taskName=='申请汇款'){
                    opt.modal.open("申请汇款",baseURL+ "bpm/remittance/add/"+id);
                }else{
                    opt.modal.open('<i class="fa icon-note"></i> <@ctx.i18n text = "选择车辆"/>',
                        baseURL  +"bpm/carinfo/select/"+taskId+"/"+id,"1600","",selectcar,true);
                }
                // if(formKey==null){
                //     opt.modal.openTab("办理任务",baseURL + "bpm/form/edit?taskId="+taskId+"&businessKey="+businessKey);
                // }else{
                //     opt.modal.open("办理任务",baseURL+formKey + "/view?taskId="+taskId+"&businessKey="+businessKey);
                // }
            }

            /**
             * 选择车辆
             * @param e
             * @param layero
             */
            function selectcar(e,layero) {
                console.log(layero)
            }
        </script>
    </@footer>
</@pageTheme>